﻿using System;
using System.Collections;
using System.Text;
using System.Configuration;
using System.Xml;

namespace GolfSigma.Inventory.Configuration
{
    public class AuthenticationSection : ConfigurationSection
    {
        [ConfigurationProperty("userAgent", IsRequired = true, DefaultValue = "")]
        public string UserAgent
        {
            get { return (string)this["userAgent"]; }
            set { this["userAgent"] = value; }
        }

        [ConfigurationProperty("accessKeyId", IsRequired = true)]
        public string AccessKeyId
        {
            get { return (string)this["accessKeyId"]; }
            set { this["accessKeyId"] = value; }
        }

        [ConfigurationProperty("secretAccessKey", IsRequired = true)]
        public string SecretAccessKey
        {
            get { return (string)this["secretAccessKey"]; }
            set { this["secretAccessKey"] = value; }
        }

        [ConfigurationProperty("serviceUrl", IsRequired = false, DefaultValue = "")]
        public string ServiceURL
        {
            get { return (string)this["serviceUrl"]; }
            set { this["serviceUrl"] = value; }
        }

        [ConfigurationProperty("proxyHost", IsRequired = false, DefaultValue = "")]
        public string ProxyHost
        {
            get { return (string)this["proxyHost"]; }
            set { this["proxyHost"] = value; }
        }

        [ConfigurationProperty("proxyPort", IsRequired = false, DefaultValue = "")]
        public string ProxyPort
        {
            get { return (string)this["proxyPort"]; }
            set { this["proxyPort"] = value; }
        }

        [ConfigurationProperty("maxErrorRetry", IsRequired = false, DefaultValue = "2")]
        public string MaxErrorRetry
        {
            get { return (string)this["maxErrorRetry"]; }
            set { this["maxErrorRetry"] = value; }
        }

        [ConfigurationProperty("requestTimeout", IsRequired = false, DefaultValue = "30")]
        public string RequestTimeout
        {
            get { return (string)this["requestTimeout"]; }
            set { this["requestTimeout"] = value; }
        }

        [ConfigurationProperty("setForwardedFor", IsRequired = false, DefaultValue = false)]
        public bool SetForwardedFor
        {
            get { return (bool)this["setForwardedFor"]; }
            set { this["setForwardedFor"] = value; }
        }

        [ConfigurationProperty("disableCompression", IsRequired = false, DefaultValue = false)]
        public bool DisableCompression
        {
            get { return (bool)this["disableCompression"]; }
            set { this["disableCompression"] = value; }
        }

        public static AuthenticationSection Load()
        {
            return Load();
        }

        /// <summary>
        /// Load the config by name
        /// </summary>
        /// <param name="name">Defaults to golfsigma/inventory</param>
        /// <returns></returns>
        public static AuthenticationSection Load(string name)
        {
            // Set default
            if (string.IsNullOrEmpty(name))
                name = "golfsigma/inventory";

            return (AuthenticationSection)ConfigurationManager.GetSection(name);
        }
    }
}
